package com.ptmall.app.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ptmall.app.R;
import com.ptmall.app.bean.OrderBean;
import com.ptmall.app.bean.ZtListBean;
import com.ptmall.app.ui.activity.GoodDetilActivity;
import com.ptmall.app.ui.activity.OrderDetilActivity;
import com.ptmall.app.view.NoScrollGridView;
import com.ptmall.app.view.NoScrollListView;

import java.util.List;


/**
 * Created by Administrator on 2018/1/12.
 */

public class ZtAdapter extends BaseAdapter {

    private Context mContext;
    private List<ZtListBean> mDataList;
    private LayoutInflater mLayoutInflater;
    private HomePageReCommendAdapter2 mHomePageReCommendAdapter;

    public ZtAdapter(Context context, List<ZtListBean> list) {
        this.mContext = context;
        this.mDataList = list;
        this.mLayoutInflater = LayoutInflater.from(mContext);
    }

    public void pushData(List<ZtListBean> list) {
        this.mDataList = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (mDataList == null) {
            return 0;
        }
        return mDataList.size();
    }


    @Override
    public Object getItem(int position) {
        return mDataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (null == convertView) {
            convertView = mLayoutInflater.inflate(R.layout.item_zt,  parent,false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        ZtListBean bean = mDataList.get(position);
        mHomePageReCommendAdapter = new HomePageReCommendAdapter2(mContext, bean.products);
        viewHolder.zt_grid.setAdapter(mHomePageReCommendAdapter);
        viewHolder.title.setText(bean.style_name);

//        viewHolder.zt_grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//                Intent intent = new Intent(mContext, GoodDetilActivity.class);
//                intent.putExtra("id",bean.products.get(i).productId);
//                mContext.startActivity(intent);
//            }
//        });

        return convertView;
    }

    class ViewHolder {

        NoScrollGridView zt_grid;
        TextView title;


        ViewHolder(View view) {
            zt_grid = (NoScrollGridView) view.findViewById(R.id.zt_grid);
            title = (TextView) view.findViewById(R.id.zt_name);
        }
    }

}
